import Manager from "../manager/Manager";
import { FMVCS } from "../fgui/fmvc/FMVCS";
import { GlobalEvent } from "./global/Global";
import { MVCS } from "../core/MVCS";
import { Platform } from "../platform/Platform";
import AppConfig from "../config/AppConfig";

const {ccclass, property} = cc._decorator;

@ccclass
export default class Launch extends FMVCS.FCtrl {
    onLoad(){
        /** 初始化fgui资源加载器 */
        fgui.addLoadHandler();
        /** 读取本地数据 */
        MVCS.Data.readData();
        /** 初始化管理类 */
        Manager.init();
        /** 初始化sdk */
        (new Platform()).init(AppConfig.platformId);
    }

    start(){
        /** 加载fgui Common package */
        this.loadCommonAsset();
    }

    loadCommonAsset(){
        fgui.UIPackage.loadPackage(`fgui/Common`, (err) => {
            if (err) return;
            this.openLoginView();
        });
    }

    /** 打开登录页 */
    openLoginView(){
        this.emit(GlobalEvent.UIListenID.UI_LoginView_Open);
    }
}
